package org.example.java.nio;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;

/**
 * Created by Juntao.Zhang on 2015/1/5.
 */
public class IntBufferTest {
  private static final int BSIZE = 60;

  public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    IntBuffer ib = bb.asIntBuffer(); // view buffer
    // 存储int的数组
    ib.put(new int[]{11, 42, 47, 99, 143, 811, 1016});

    // 绝对位置读写
    System.out.println(ib.get(3));

    System.out.println("*******************************");
    System.out.println(ib.limit());
    ib.put(3, 1811);
    ib.put(8, 222);
    ib.flip();
    System.out.println(ib.limit());
    System.out.println("*******************************");
    //ib.rewind();

    while (ib.hasRemaining()) {
      int i = ib.get();
      System.out.println(i);
    }
  }
}
